//
//  NewOneWayCell.m
//  carcareIOS
//
//  Created by tianxing on 16/2/26.
//  Copyright © 2016年 baozun. All rights reserved.
//
#define CELL_HEIGHT  (138 *__MAIN_RATIO_H_667)
#import "NewOneWayCell.h"

@interface NewOneWayCell ()

@property (nonatomic ,strong) UIView  *startePointView; // 开始点
@property (nonatomic ,strong) UIView  *endPointView;    // 结束点
@property (nonatomic ,strong) UILabel *mileageLabel;    // 里程分数
@property (nonatomic ,strong) UILabel *starteLabel;     // 开始的具体位置
@property (nonatomic ,strong) UILabel *endLabel;        // 结束的具体位置
@property (nonatomic ,strong) UILabel *detailLabel;     // 行程的详细信息

@end

@implementation NewOneWayCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self setUpView];
    }
    return self;
}
+(CGFloat)cellHeight{
    return CELL_HEIGHT ;
}
- (void)setUpView
{
    
    self.frame = CGRectMake(0, 0, __MAIN_WIDTH, CELL_HEIGHT);
    self.backgroundColor = COLOR_HEXSTRING(@"#F6F6F9");
    
    //背景颜色
    [[[UIView viewWithFrame:CGRectMake(0, 0, __MAIN_WIDTH, 0.5 * __MAIN_RATIO_375)] resetBackgroundColor:COLOR_HEXSTRING(@"#F9F5EC")] setupOnView:self];
    
    CGFloat BGviewHeight = 130 * __MAIN_RATIO_375;
    UIView *BGview = [[[UIView viewWithFrame:CGRectMake(0, 8 * __MAIN_RATIO_375, __MAIN_WIDTH, BGviewHeight)] resetBackgroundColor:[UIColor whiteColor]] setupOnView:self];
    [self addSubview:BGview];
    // 里程分数(例如：96)
    CGFloat mileageLabelX = 15 * __MAIN_RATIO_375;
    
    CGFloat mileageLabelY = 35 * __MAIN_RATIO_375;
    
    CGFloat mileageLabelWidth  = 50 * __MAIN_RATIO_375;

    CGFloat mileageLabelHeight = 35 * __MAIN_RATIO_375;
    
    self.mileageLabel = [Factory labelWithFrame:CGRectMake(mileageLabelX, mileageLabelY,mileageLabelWidth, mileageLabelHeight) font:FONT_DEFAULT_Light(25) text:@"" textColor:COLOR_HEXSTRING(@"#181818") onView:BGview textAlignment:NSTextAlignmentCenter];
    
    //起点标、 起点 、 起始位置
    
    _startePointView = [[[UIView viewWithFrame:CGRectMake(self.mileageLabel.right + 10 * __MAIN_RATIO_375, 31 * __MAIN_RATIO_375, 9 * __MAIN_RATIO_375, 9 * __MAIN_RATIO_375)] resetBackgroundColor:COLOR_HEXSTRING(@"#1ed162")] setupOnView:BGview];
    _startePointView.clipsToBounds = YES;
    _startePointView.layer.cornerRadius = 4;
    
    UILabel *startePointLabel = [Factory labelWithFrame:CGRectMake(self.mileageLabel.right + 30 * __MAIN_RATIO_375, 26 * __MAIN_RATIO_375, 25 * __MAIN_RATIO_375, 17.5 * __MAIN_RATIO_375) font:FONT_DEFAULT_Light(14) text:@"起:" textColor:COLOR_HEXSTRING(@"#181818") onView:BGview textAlignment:NSTextAlignmentLeft];

    self.starteLabel = [Factory labelWithFrame:CGRectMake(startePointLabel.right + 5 * __MAIN_RATIO_375, startePointLabel.top,230 * __MAIN_RATIO_375 , 17.5 * __MAIN_RATIO_375) font:FONT_DEFAULT_Light(14) text:@"" textColor:COLOR_HEXSTRING(@"#181818") onView:BGview textAlignment:NSTextAlignmentLeft];
    self.starteLabel.numberOfLines = 1;
    
    // 结束标 、终点 、终点位置
    
    _endPointView = [[[UIView viewWithFrame:CGRectMake(self.mileageLabel.right + 10 * __MAIN_RATIO_375, _startePointView.bottom + 26 * __MAIN_RATIO_375,8 * __MAIN_RATIO_375 , 8 * __MAIN_RATIO_375)] resetBackgroundColor:COLOR_HEXSTRING(@"#f05f33")] setupOnView:BGview];
    _endPointView.clipsToBounds = YES;
    _endPointView.layer.cornerRadius = 4;
    
    UILabel *endPointLabel  = [Factory labelWithFrame:CGRectMake(self.mileageLabel.right + 30 * __MAIN_RATIO_375, startePointLabel.bottom + 16 * __MAIN_RATIO_375, 25 * __MAIN_RATIO_375, 17.5 * __MAIN_RATIO_375) font:FONT_DEFAULT_Light(14) text:@"终:" textColor:COLOR_HEXSTRING(@"#181818") onView:BGview textAlignment:NSTextAlignmentLeft];
    
    
    
    self.endLabel = [Factory labelWithFrame:CGRectMake(endPointLabel.right + 5 *__MAIN_RATIO_375, self.starteLabel.bottom + 16 *__MAIN_RATIO_375, 230 * __MAIN_RATIO_375, 17.5 * __MAIN_RATIO_375) font:FONT_DEFAULT_Light(14) text:@"" textColor:COLOR_HEXSTRING(@"#181818") onView:BGview textAlignment:NSTextAlignmentLeft];
    self.endLabel.textAlignment = NSTextAlignmentJustified;
    self.endLabel.numberOfLines = 1;

    //出发点，行驶多少公里 ，占用多少分钟
    
//    NSString *modelString = [NSString stringWithFormat:@"15:21出发 21公里，49分钟"];
    self.detailLabel = [Factory labelWithFrame:CGRectMake(endPointLabel.left,self.endLabel.bottom + 10 * __MAIN_RATIO_375, 250 * __MAIN_RATIO_375, 15 * __MAIN_RATIO_375) font:FONT_DEFAULT_Light(12) text:@"" textColor:COLOR_HEXSTRING(@"#919191") onView:BGview textAlignment:NSTextAlignmentLeft];

    // 起点和终点之间的虚线
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    [shapeLayer setBounds:self.bounds];
    [shapeLayer setPosition:self.center];
    [shapeLayer setFillColor:[[UIColor clearColor] CGColor]];
    [shapeLayer setStrokeColor:[COLOR_HEXSTRING(@"#949494") colorWithAlphaComponent:0.7].CGColor];
    
    [shapeLayer setLineWidth:1.f];
    [shapeLayer setLineJoin:kCALineJoinRound];
    // 1 = 线的宽度 1 = 每条线的间距
    
    [shapeLayer setLineDashPattern:
     [NSArray arrayWithObjects:[NSNumber numberWithInt:2],[NSNumber numberWithInt:2],nil]];
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, _startePointView.centerX, _startePointView.bottom + 4.5);
    CGPathAddLineToPoint(path, NULL, _endPointView.centerX,_endPointView.top - 4);
    [shapeLayer setPath:path];
    CGPathRelease(path);
    [BGview.layer addSublayer:shapeLayer];
}

- (void)setModel:(OneDriveModel *)model{
    _model = model;
    self.mileageLabel.text = STRING_INT(model.mark);    // 里程分数
    self.starteLabel.text = model.startPlace;           // 开始的具体位置
    self.endLabel.text = model.endPlace;                // 结束的具体位置
    
    NSString *startTime = [model.startTime substringWithRange:NSMakeRange(11, 5)];
    self.detailLabel.text = [NSString stringWithFormat:@"%@出发 %.0f公里, 油费%.0f元",startTime,model.mile,model.fuelCost];
    
}

- (void)dealloc{
    
    self.model = nil;
}


@end
